package com.szholly.data.general.interceptor;

import com.szholly.data.general.ITable;

/**
 * 定义查询拦截基类
 * 
 */
public abstract class DbSelectInterceptorClass extends DbInterceptorClass
		implements IDbSelectInterceptor {

	/**
	 * 数据查询前
	 */
	public abstract void BeforeDbSelectOption(ITable table, Object queryFilter);

	/**
	 * 查询出错时
	 */
	public abstract void DbSelectOptionException(ITable table,
			Object queryFilter, Exception ex);

	/**
	 * 数据查询后
	 */
	public abstract void AfterDbSelectOption(ITable table, Object queryFilter, Object queryData);

	/**
	 * 数据查询前
	 * 
	 * @param table
	 * @param queryFilter
	 * @return
	 */
	public static Object BeforeDbSelectOptionEx(ITable table, Object queryFilter) {
		for (IDbSelectInterceptor editItem : InterceptorRegister.dbSelectInterceptor) {
			if (editItem != null
					&& editItem.contains(table.getMetadataTableName())) {
				editItem.BeforeDbSelectOption(table, queryFilter);
			}
		}
		return null;
	}

	/**
	 * 查询出错时
	 * 
	 * @param table
	 * @param queryFilter
	 * @param selectType
	 * @param ex
	 */
	public static void DbSelectOptionExceptionEx(ITable table,
			Object queryFilter, Exception ex) {
		for (IDbSelectInterceptor editItem : InterceptorRegister.dbSelectInterceptor) {
			if (editItem != null && editItem.contains(table.getTableName()))
				editItem.DbSelectOptionException(table, queryFilter, ex);
		}
	}

	/**
	 * 数据查询后
	 */
	public static void AfterDbSelectOptionEx(ITable table, Object queryFilter, Object queryData) {
		for (IDbSelectInterceptor editItem : InterceptorRegister.dbSelectInterceptor) {
			if (editItem != null && editItem.contains(table.getTableName())) {
				editItem.AfterDbSelectOption(table, queryFilter, queryData);
			}
		}
	}
}